<template>
  <div class="login-container">
    <h2>登录页面</h2>

    <el-input v-model="userName" placeholder="用户名"></el-input>
    <el-input v-model="passWord" placeholder="密码"></el-input>
    <el-button type="primary" size="default" @click="login">登录</el-button>
  </div>
</template>

<script setup>
import { ref } from "vue";
import { useRouter } from "vue-router";
import { useStore } from "vuex";

// 初始化 store 和 router
const store = useStore();
const router = useRouter();

const userName = ref("");
const passWord = ref("");

// const login = async () => {
//   let loginForm = { userName: userName.value, passWord: passWord.value };
//   localStorage.setItem("loginForm", JSON.stringify(loginForm));
// };
const login = () => {
  store.commit(
    "setUserInfo",
    {
      userName: userName.value,
      passWord: passWord.value,
    }
  );

  // 设置本地存储数据 localStorage.setItem('key', 'value');
  localStorage.setItem(
    "loginData",
    JSON.stringify({
      userName: userName.value,
      passWord: passWord.value,
    })
  );
  // window.location.href = "/dashboard";

  router.push({
    path: "/dashboard",
  });
};
</script>
